
module.exports = {
  isNull: (value, name) => {
    if (!value) {
      throw new Error(name + "不能为空");
    }
  },

  len(value, options) {
    const { min, max, text } = options;
    if (value.length < min || value.length > max) {
      throw new Error(text + `长度必须在${min}到${max}位之间`);
    }
  },

  isValidIDCard(value) {
    const regex = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
    if (value && !regex.test(value)) {
      throw new Error('身份证号码格式不正确');
    }
  },

  regValidator(value, options) {

    const { regExps } = options

    for (let item of regExps) {
        if (!item.regExp.test(value)) {
            throw new Error(reg.message);
        }
    }
  }
};
